extends Node

var try_count : int = 3
var levels = []
var current_level_index = 0
var is_pass_reload : bool = true
var disable_play : bool

func _ready() -> void:
	print("加载pck包：",ProjectSettings.load_resource_pack("./chase2.pck"))
	levels = _get_folder_list()
	print(levels)
	disable_play = levels.is_empty()
	print("能否进入游戏",disable_play)
	assert(levels.size()>0,"关卡表格数量为0，请检查是否有存档！")

func _read_file(file_name : String) -> Dictionary :
	var file = FileAccess.open("res://datas/"+file_name, FileAccess.READ)
	return file.get_var()

func _write_file(file_name : String, data : Dictionary) -> void :
	if not file_name.ends_with(".res") : file_name += ".res"
	var file = FileAccess.open("./datas/"+file_name, FileAccess.WRITE)
	file.store_var(data)

func _get_folder_list() -> Array :
	var dir = DirAccess.open("res://datas/")
	return dir.get_files()

func _get_next_level() -> String :
	if is_pass_reload :
		current_level_index += 1
	else :
		is_pass_reload = true
	return levels.get(wrapi(current_level_index,0,levels.size()))
